<?php


/**
* Puree CMS
* http://www.molotsoft.ru
*
* @package Puree_CMS
* @subpackage Admin/Behaviors
* @author Ivan Chistyakov <ivan@molotsoft.ru>
* @version $Id: field_name_disabled.php 1038 2010-03-23 13:45:00Z molotsoft@gmail.com $
* @link $HeadURL: http://puree-cms.googlecode.com/svn/trunk/plugins/admin/models/behaviors/field_name_disabled.php $
*/


class FieldNameDisabledBehavior extends ModelBehavior {

/******************************************************************************/

var $settings = array();

/******************************************************************************/

function setup(&$Model, $settings = array()) {
	$this->settings[$Model->name] = (array)$settings;
}

/******************************************************************************/

function getDisabled(&$Model, $id = NULL) {
	return $Model->hasField('disabled') ? (bool)$Model->getField('disabled', $id) : NULL;
}

function setDisabled(&$Model, $value, $id = NULL) {
	return $Model->hasField('disabled') ? $Model->setField('disabled', (bool)$value, $id) : FALSE;
}

/******************************************************************************/

function disable(&$Model, $id = NULL) {
	return $this->setDisabled($Model, TRUE, $id);
}

function enable(&$Model, $id = NULL) {
	return $this->setDisabled($Model, FALSE, $id);
}

function toggleDisabled(&$Model, $id = NULL) {
	return $this->setDisabled($Model, !$this->getDisabled($Model, $id), $id);
}

/******************************************************************************/

}


?>